home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / sys5 / iscwmpst.z / iscwmpst / tcp / src / tcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-10  |  10.1 KB  |  295 lines

  1. /* @(#) $Header: tcp.h,v 1.6 91/05/09 07:38:55 deyke Exp $ */
  2.  
  3. #ifndef _TCP_H
  4. #define _TCP_H
  5.  
  6. /* TCP implementation. Follows RFC 793 as closely as possible */
  7. #ifndef _GLOBAL_H
  8. #include "global.h"
  9. #endif
  10.  
  11. #ifndef _MBUF_H
  12. #include "mbuf.h"
  13. #endif
  14.  
  15. #ifndef _IFACE_H
  16. #include "iface.h"
  17. #endif
  18.  
  19. #ifndef _INTERNET_H
  20. #include "internet.h"
  21. #endif
  22.  
  23. #ifndef _IP_H
  24. #include "ip.h"
  25. #endif
  26.  
  27. #ifndef _NETUSER_H
  28. #include "netuser.h"
  29. #endif
  30.  
  31. #ifndef _TIMER_H
  32. #include "timer.h"
  33. #endif
  34.  
  35. #define DEF_WND 2048    /* Default receiver window */
  36. #define RTTCACHE 16     /* # of TCP round-trip-time cache entries */
  37. #define DEF_MSS 512     /* Default maximum segment size */
  38. #define DEF_RTT 5000    /* Initial guess at round trip time (5 sec) */
  39. #define MSL2    30      /* Guess at two maximum-segment lifetimes */
  40. #define TCP_MAXOPT      40      /* Largest option field, bytes */
  41.  
  42. #define geniss()        ((int32)msclock() << 12) /* Increment clock at 4 MB/sec */
  43.  
  44. /* Number of consecutive duplicate acks to trigger fast recovery */
  45. #define TCPDUPACKS      3
  46.  
  47. /* Round trip timing parameters */
  48. #define AGAIN   8       /* Average RTT gain = 1/8 */
  49. #define LAGAIN  3       /* Log2(AGAIN) */
  50. #define DGAIN   4       /* Mean deviation gain = 1/4 */
  51. #define LDGAIN  2       /* log2(DGAIN) */
  52.  
  53. /* TCP segment header -- internal representation
  54.  * Note that this structure is NOT the actual header as it appears on the
  55.  * network (in particular, the offset and checksum fields are missing).
  56.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  57.  */
  58. struct tcp {
  59.     int16 source;   /* Source port */
  60.     int16 dest;     /* Destination port */
  61.     int32 seq;      /* Sequence number */
  62.     int32 ack;      /* Acknowledgment number */
  63.     struct {
  64.         char congest;   /* Echoed IP congestion experienced bit */
  65.         char urg;
  66.         char ack;
  67.         char psh;
  68.         char rst;
  69.         char syn;
  70.         char fin;
  71.     } flags;
  72.     int16 wnd;                      /* Receiver flow control window */
  73.     int16 checksum;                 /* Checksum */
  74.     int16 up;                       /* Urgent pointer */
  75.     int16 mss;                      /* Optional max seg size */
  76.     char options[TCP_MAXOPT];       /* Options field */
  77.     int optlen;                     /* Length of options field, bytes */
  78. };
  79. /* TCP options */
  80. #define EOL_KIND        0
  81. #define NOOP_KIND       1
  82. #define MSS_KIND        2
  83.  
  84. #define TCPLEN          20
  85. #define MSS_LENGTH      4
  86. /* Resequencing queue entry */
  87. struct reseq {
  88.     struct reseq *next;     /* Linked-list pointer */
  89.     struct tcp seg;         /* TCP header */
  90.     struct mbuf *bp;        /* data */
  91.     int16 length;           /* data length */
  92.     char tos;               /* Type of service */
  93. };
  94. #define NULLRESEQ       (struct reseq *)0
  95.  
  96. /* TCP connection control block */
  97. struct tcb {
  98.     struct tcb *next;       /* Linked list pointer */
  99.  
  100.     struct connection conn;
  101.  
  102.     char state;     /* Connection state */
  103.  
  104. /* These numbers match those defined in the MIB for TCP connection state */
  105. #define TCP_CLOSED              1
  106. #define TCP_LISTEN              2
  107. #define TCP_SYN_SENT            3
  108. #define TCP_SYN_RECEIVED        4
  109. #define TCP_ESTABLISHED         5
  110. #define TCP_FINWAIT1            6
  111. #define TCP_FINWAIT2            7
  112. #define TCP_CLOSE_WAIT          8
  113. #define TCP_LAST_ACK            9
  114. #define TCP_CLOSING             10
  115. #define TCP_TIME_WAIT           11
  116.  
  117.     char reason;            /* Reason for closing */
  118. #define NORMAL          0       /* Normal close */
  119. #define RESET           1       /* Reset by other end */
  120. #define TIMEOUT         2       /* Excessive retransmissions */
  121. #define NETWORK         3       /* Network problem (ICMP message) */
  122.  
  123. /* If reason == NETWORK, the ICMP type and code values are stored here */
  124.     char type;
  125.     char code;
  126.  
  127.     /* Send sequence variables */
  128.     struct {
  129.         int32 una;      /* First unacknowledged sequence number */
  130.         int32 nxt;      /* Next sequence num to be sent for the first time */
  131.         int32 ptr;      /* Working transmission pointer */
  132.         int32 wl1;      /* Sequence number used for last window update */
  133.         int32 wl2;      /* Ack number used for last window update */
  134.         int16 wnd;      /* Other end's offered receive window */
  135.         int16 up;       /* Send urgent pointer */
  136.     } snd;
  137.     int32 iss;              /* Initial send sequence number */
  138.     int32 resent;           /* Count of bytes retransmitted */
  139.     int16 cwind;            /* Congestion window */
  140.     int16 ssthresh;         /* Slow-start threshold */
  141.     int dupacks;            /* Count of duplicate (do-nothing) ACKs */
  142.  
  143.     /* Receive sequence variables */
  144.     struct {
  145.         int32 nxt;      /* Incoming sequence number expected next */
  146.         int16 wnd;      /* Our offered receive window */
  147.         int16 up;       /* Receive urgent pointer */
  148.     } rcv;
  149.     int32 irs;              /* Initial receive sequence number */
  150.     int32 rerecv;           /* Count of duplicate bytes received */
  151.     int16 mss;              /* Maximum segment size */
  152.  
  153.     int16 window;           /* Receiver window and send queue limit */
  154.  
  155.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt));
  156.         /* Call when "significant" amount of data arrives */
  157.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt));
  158.         /* Call when ok to send more data */
  159.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new));
  160.         /* Call when connection state changes */
  161.     struct {                /* Control flags */
  162.         char force;     /* We owe the other end an ACK or window update */
  163.         char clone;     /* Server-type TCB, cloned on incoming SYN */
  164.         char retran;    /* A retransmission has occurred */
  165.         char active;    /* TCB created with an active open */
  166.         char synack;    /* Our SYN has been acked */
  167.         char rtt_run;   /* We're timing a segment */
  168.         char congest;   /* Copy of last IP congest bit received */
  169.     } flags;
  170.     char tos;               /* Type of service (for IP) */
  171.     int backoff;            /* Backoff interval */
  172.  
  173.     struct mbuf *rcvq;      /* Receive queue */
  174.     struct mbuf *sndq;      /* Send queue */
  175.     int16 rcvcnt;           /* Count of items on rcvq */
  176.     int16 sndcnt;           /* Number of unacknowledged sequence numbers on
  177.                  * sndq. NB: includes SYN and FIN, which don't
  178.                  * actually appear on sndq!
  179.                  */
  180.  
  181.     struct reseq *reseq;    /* Out-of-order segment queue */
  182.     struct timer timer;     /* Retransmission timer */
  183.     int32 rtt_time;         /* Stored clock values for RTT */
  184.     int32 rttseq;           /* Sequence number being timed */
  185.     int32 srtt;             /* Smoothed round trip time, milliseconds */
  186.     int32 mdev;             /* Mean deviation, milliseconds */
  187.     int32 lastactive;       /* Clock time when xmtr last active */
  188.  
  189.     int user;               /* User parameter (e.g., for mapping to an
  190.                  * application control block
  191.                  */
  192. };
  193. #define NULLTCB (struct tcb *)0
  194. /* TCP round-trip time cache */
  195. struct tcp_rtt {
  196.     int32 addr;             /* Destination IP address */
  197.     int32 srtt;             /* Most recent SRTT */
  198.     int32 mdev;             /* Most recent mean deviation */
  199. };
  200. #define NULLRTT (struct tcp_rtt *)0
  201. extern struct tcp_rtt Tcp_rtt[];
  202.  
  203. /* TCP statistics counters */
  204. struct tcp_stat {
  205.     int16 runt;             /* Smaller than minimum size */
  206.     int16 checksum;         /* TCP header checksum errors */
  207.     int16 conout;           /* Outgoing connection attempts */
  208.     int16 conin;            /* Incoming connection attempts */
  209.     int16 resets;           /* Resets generated */
  210.     int16 bdcsts;           /* Bogus broadcast packets */
  211. };
  212. extern struct mib_entry Tcp_mib[];
  213. #define tcpRtoAlgorithm Tcp_mib[1].value.integer
  214. #define tcpRtoMin       Tcp_mib[2].value.integer
  215. #define tcpRtoMax       Tcp_mib[3].value.integer
  216. #define tcpMaxConn      Tcp_mib[4].value.integer
  217. #define tcpActiveOpens  Tcp_mib[5].value.integer
  218. #define tcpPassiveOpens Tcp_mib[6].value.integer
  219. #define tcpAttemptFails Tcp_mib[7].value.integer
  220. #define tcpEstabResets  Tcp_mib[8].value.integer
  221. #define tcpCurrEstab    Tcp_mib[9].value.integer
  222. #define tcpInSegs       Tcp_mib[10].value.integer
  223. #define tcpOutSegs      Tcp_mib[11].value.integer
  224. #define tcpRetransSegs  Tcp_mib[12].value.integer
  225. #define tcpInErrs       Tcp_mib[14].value.integer
  226. #define tcpOutRsts      Tcp_mib[15].value.integer
  227. #define NUMTCPMIB       15
  228.  
  229. extern struct tcb *Tcbs;
  230. extern int16 Tcp_mss;
  231. extern int16 Tcp_window;
  232. extern int32 Tcp_irtt;
  233. extern int Tcp_trace;
  234. extern int Tcp_syndata;
  235. extern char *Tcpstates[];
  236. extern char *Tcpreasons[];
  237.  
  238. /* In tcpcmd.c: */
  239. void st_tcp __ARGS((struct tcb *tcb));
  240.  
  241. /* In tcphdr.c: */
  242. struct mbuf *htontcp __ARGS((struct tcp *tcph,struct mbuf *data,
  243.     struct pseudo_header *ph));
  244. int ntohtcp __ARGS((struct tcp *tcph,struct mbuf **bpp));
  245.  
  246. /* In tcpin.c: */
  247. void reset __ARGS((struct ip *ip,struct tcp *seg));
  248. void send_syn __ARGS((struct tcb *tcb));
  249. void tcp_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  250.     int rxbroadcast));
  251. void tcp_icmp __ARGS((int32 icsource,int32 source,int32 dest,
  252.     int type,int code,struct mbuf **bpp));
  253.  
  254. /* In tcpsubr.c: */
  255. void close_self __ARGS((struct tcb *tcb,int reason));
  256. struct tcb *create_tcb __ARGS((struct connection *conn));
  257. struct tcb *lookup_tcb __ARGS((struct connection *conn));
  258. void rtt_add __ARGS((int32 addr,int32 rtt));
  259. struct tcp_rtt *rtt_get __ARGS((int32 addr));
  260. int seq_ge __ARGS((int32 x,int32 y));
  261. int seq_gt __ARGS((int32 x,int32 y));
  262. int seq_le __ARGS((int32 x,int32 y));
  263. int seq_lt __ARGS((int32 x,int32 y));
  264. int seq_within __ARGS((int32 x,int32 low,int32 high));
  265. void setstate __ARGS((struct tcb *tcb,int newstate));
  266. void tcp_garbage __ARGS((int red));
  267.  
  268. /* In tcpout.c: */
  269. void tcp_output __ARGS((struct tcb *tcb));
  270.  
  271. /* In tcptimer.c: */
  272. int32 backoff __ARGS((int n));
  273. void tcp_timeout __ARGS((void *p));
  274.  
  275. /* In tcpuser.c: */
  276. int close_tcp __ARGS((struct tcb *tcb));
  277. int del_tcp __ARGS((struct tcb *tcb));
  278. int kick __ARGS((int32 addr));
  279. int kick_tcp __ARGS((struct tcb *tcb));
  280. struct tcb *open_tcp __ARGS((struct socket *lsocket,struct socket *fsocket,
  281.     int mode,int window,
  282.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt)),
  283.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt)),
  284.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new)),
  285.     int tos,int user));
  286. int recv_tcp __ARGS((struct tcb *tcb,struct mbuf **bpp,int cnt));
  287. void reset_all __ARGS((void));
  288. void reset_tcp __ARGS((struct tcb *tcb));
  289. int send_tcp __ARGS((struct tcb *tcb,struct mbuf *bp));
  290. int space_tcp __ARGS((struct tcb *tcb));
  291. char *tcp_port __ARGS((int n));
  292. int tcpval __ARGS((struct tcb *tcb));
  293.  
  294. #endif  /* _TCP_H */
  295.